module test_ioevent;

import dactor.scheduler;
import dactor.coroutine;
import dactor.eventlet;
import dactor.log;
import core.sys.posix.unistd;
import std.stdio;

void test_io_event() {
    while (true) {
        Event ev = new Event(0, Event.READ, 3000);
        int ret = ev.wait();
        assert(ret == Event.READ || ret == Event.TIMEOUT);

        logDebug("wait result: %d", ret);
        if (ret & Event.TIMEOUT) {
            logDebug("wait timeout");
            continue;
        }

        char buffer[1024];
        int len = .read(0, buffer.ptr, buffer.length);
        if (len <= 0) {
            logDebug("receive fail");
            break;
        }
        logDebug("received: %s(%d)", buffer[0..len], len);
    }
}


void main() {
    spawn(&test_io_event);

    Scheduler.instance.run();
}

